package com.logisticsmanagement.services;


import static com.logisticsmanagement.utils.GlobelValue.*;

import java.util.ArrayList;
import java.util.List;

import com.logisticsmanagement.dao.CityDao;
import com.logisticsmanagement.domain.City;
import com.logisticsmanagement.vo.BaseResponse;
import com.logisticsmanagement.vo.VoCity;
import com.logisticsmanagement.vo.VoIndent;

public class CityService {
	private CityDao cityDao=new CityDao();
	
	/**
	 * jundge city exist or not
	 * @return
	 */
	public boolean cityIsExit(City city){
		
		City queryCity=new City();
		if((queryCity=cityDao.selectById(city.getCityID()))!=null){
			return true;//return true if have the city id 
		}else{
			return false;//return ture if password equals password selected by sql 
			}
	}
	
	/**
	 *  acquire city information that specialize in the cityID
	 * @param cityID
	 * @return VoCity
	 */
	public BaseResponse<VoCity> queryCity(int cityID){
		City city=new City();
		VoCity voCity=new VoCity();
		
		List<VoCity> listVoCity=new ArrayList<VoCity>();
		//set default value
		BaseResponse<VoCity> baseResponseVoCity=new BaseResponse<VoCity>(QUERY_NOT_FOUND,
				QUERY_NOT_FOUND_DESCRIPTON,listVoCity);
		

		city=cityDao.selectById(cityID);
		
		voCity.setCityID(city.getCityID());
		voCity.setCityName(city.getName());
		//query city asset;invoke other method getCityAsset()
		voCity.setAsset(this.getCityAsset(cityID));
		listVoCity.add(voCity);
		baseResponseVoCity.setResponseCode(QUERY_SUCCESS);
		baseResponseVoCity.setResponseDescription(QUERY_SUCCESS_DESCRIPTON);
		return baseResponseVoCity;		 
	}
	
	/**
	 * update city information which pass in parameter
	 * @param newUser
	 * @return
	 */
	public boolean updateCityInfo(City newCity){
		
		return cityDao.update(newCity);
	}
	
	/**
	 * return boolean whether special city is deleted 
	 */
	public boolean deleteCity(City city){
		//in service model ,set city.isDelete and prepareDalete
		//only set prepareDelete=true;
		city.setPrepareDelete(false);
		return cityDao.update(city);
	}
	
	/**
	 * get deliveryStation or City asset.
	 * @param cityID
	 * @return
	 */
	private double getCityAsset(int cityID){
		double cityAsset=0;
		
		return cityAsset;
		
		
	}
}
